package com.activity.shop;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.activity.App;
import com.activity.bean.UserBean;
import com.api.param.GroupParam;
import com.api.viewModel.StoreVM;
import com.example.apple.ddhr_new.R;
import com.example.apple.ddhr_new.utils.ImageViewUtil;
import com.example.lzbase.BaseViewModelActivity;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AttanceGroupActivity extends BaseViewModelActivity<StoreVM> {


    @BindView(R.id.tv_name)
    ImageView tvName;
    @BindView(R.id.r_name)
    RelativeLayout rName;
    @BindView(R.id.l_group)
    LinearLayout lGroup;
    @BindView(R.id.iv_check_kaoqin)
    ImageView ivCheckKaoqin;
    @BindView(R.id.l_time)
    LinearLayout lTime;
    @BindView(R.id.iv_check_range)
    ImageView ivCheckRange;
    @BindView(R.id.l_range)
    LinearLayout lRange;
    @BindView(R.id.tv_my_name)
    TextView tvMyName;
    @BindView(R.id.tv_group_name)
    TextView tvGroupName;
    @BindView(R.id.l_check_range)
    LinearLayout lCheckRange;
    @BindView(R.id.l_check_time)
    LinearLayout lCheckTime;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_address)
    TextView tvAddress;

    @Override
    protected int titleText() {
        return R.string.kaoqin_guize;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_attance_group;
    }

    @Override
    protected void created(@Nullable Bundle savedInstanceState) {
        super.created(savedInstanceState);
        ivCheckKaoqin.setSelected(true);
        ivCheckRange.setSelected(true);

        UserBean.AttendancegroupinfoBean bean = App.getInstance().getAccount().getAttendancegroupinfo().get(0);
        tvGroupName.setText("考勤组:" + bean.getAttendancegroupname());

        ImageViewUtil.loadCircleImage(App.getInstance().getAccount().getUsericon(),tvName,this);
        tvMyName.setText(App.getInstance().getAccount().getUsernickname());

        GroupParam param = new GroupParam();
        param.attendancegroupid = App.getInstance().getAccount().getAttendancegroupinfo().get(0).getAttendancegroupid();
        addSubscription(viewModel.getGroupInfo(param));
        viewModel.attanceGroupInfo.observe(this, res -> {


            tvTime.setText(res.get(0).getClassDay());
            tvAddress.setText(res.get(0).getClassAddressn());
        });


    }

    @OnClick({R.id.l_check_time, R.id.l_check_range})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.l_check_time:
                ivCheckKaoqin.setSelected(!ivCheckKaoqin.isSelected());
                if (ivCheckKaoqin.isSelected()) {
                    lTime.setVisibility(View.VISIBLE);
                } else {
                    lTime.setVisibility(View.GONE);
                }
                break;
            case R.id.l_check_range:
                ivCheckRange.setSelected(!ivCheckRange.isSelected());
                if (ivCheckRange.isSelected()) {
                    lRange.setVisibility(View.VISIBLE);
                } else {
                    lRange.setVisibility(View.GONE);
                }
                break;
        }
    }


}
